#!/usr/bin/env python
# -*- coding: utf-8 -*

from clutter import Label 
from box import LBox
import os
import alwaysontop

mpd_host = "192.168.1.99"
mpd_port = "6600"
mpd_command_base = "MPD_HOST=%s mpc" %mpd_host

class MpdController(LBox):
    def __init__(self):
        LBox.__init__(self, orientation="vertical")
        self._add_button("Previous", "prev")
        self._add_button("Play", "toggle")
        self._add_button("Next", "next")
        self._add_button("Random", "random on")
        self._build_background()

    def _add_button(self, name, command):
        btn = MpdButton(name, command)
        self.add(btn)

class MpdButton(Label):
    def __init__(self, name, command):
        Label.__init__(self)
        self.name = name
        self.command = command
        self.set_font_name(alwaysontop.font_name)
        self.set_text(name)
        self.set_color(alwaysontop.font_color)
        self.set_reactive(True)
        self.connect("button-press-event", self.mpd_do, command)

    def mpd_do(self, source, event, command):
        os.system("%s %s" %(mpd_command_base, command))
